package suse.hotel.admin.admin.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import suse.hotel.admin.admin.Entity.Order;
import suse.hotel.admin.admin.Mapper.OrderMapper;
import suse.hotel.admin.admin.Provider.EmailProvide;
import suse.hotel.admin.admin.Service.OrderService;

@Controller
public class OrderController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderService orderService;
    @Autowired
    EmailProvide emailProvide;

    @RequestMapping("/sendTo")
    @ResponseBody
    public void sendTo(int orderId,String email){
        emailProvide.sendTo(email,orderId);
    }

    @RequestMapping("/order-list")
    public String selorders() {
        return "order-list";
    }

    @RequestMapping("/orderShow")
    @ResponseBody
    public String listorders(@RequestParam(defaultValue="1") int page, @RequestParam(defaultValue="10") int limit) {
        String re=orderService.selOrders(page,limit);
        return re;
    }
    @RequestMapping("/orderSearch")
    @ResponseBody
    public String searchOrder(@RequestParam(defaultValue="1") int page, @RequestParam(defaultValue="10") int limit,String key) {
        return orderService.selOrdersById(page,limit,key);
    }
    @RequestMapping("/delOrder")
    @ResponseBody
    public String delOreder(int id){
        if(orderMapper.delOrder(id)!=0)
            return "true";
        return "false";
    }
    @RequestMapping("/editOrder")
    @ResponseBody
    public int editUser(Order order) {
        int re= orderMapper.editOrder(order);
        return re;
    }
    @RequestMapping("/order-list1")
    public String orderList1() {
        return "order-list1";
    }

    @RequestMapping("/order-add")
    public String orderAdd() {
        return "order-add";
    }

    @RequestMapping("/order-view")
    public String orderView() {
        return "order-view";
    }
}
